//
//  MainTabBarController.m
//  Findif
//
//  Created by Cicel Chen on 2018/10/18.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "MainTabBarController.h"
#import "MainNavigationController.h"
//#import "HomeViewController.h"
//#import "NearByViewController.h"
//#import "ChatViewController.h"
//#import "MyselfViewController.h"

@interface MainTabBarController ()

@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 为了避免push时导航条出现的黑块
    self.view.backgroundColor = [UIColor whiteColor];
//    [[UITabBar appearance] setTintColor:[UIColor colorWithHex:0x075ED0]];//tabBarItem选中颜色
    [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
    
    [UITabBar appearance].translucent = NO;
    
    [self layoutUI];
}


- (void)layoutUI {
    
    NSDictionary *dic1 = @{@"vcName":@"HomeViewController",@"title":@"首页",@"imageName":@"house"};
    NSDictionary *dic2 = @{@"vcName":@"SquareViewController",@"title":@"广场",@"imageName":@"广场"};
    NSDictionary *dic3 = @{@"vcName":@"ChatViewController",@"title":@"圈子",@"imageName":@"圈子"};
    NSDictionary *dic4 = @{@"vcName":@"MyselfViewController",@"title":@"我的",@"imageName":@"个人中心"};
    
    //    //判断是否有登录过
    //    Account* account = [YSAccountTool account];
    //    NSString *personVcName;
    //    if(account){
    //        personVcName = @"MineViewController";
    //    }else{
    //        personVcName = @"LoginViewController";
    //    }
    
    UIViewController *vc1 = [self generateVCWithDic:dic1];
    UIViewController *vc2 = [self generateVCWithDic:dic2];
    UIViewController *vc3 = [self generateVCWithDic:dic3];
    UIViewController *vc4 = [self generateVCWithDic:dic4];
    
    //改变tabbarController 文字选中颜色(默认渲染为蓝色)
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:ZRBlackColor} forState:UIControlStateNormal];//ColorWithRGB(0xFFE056)
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:ZRBlackColor} forState:UIControlStateSelected];
    
    self.viewControllers = @[vc1,vc2,vc3,vc4];
    
}

-(UIViewController *)generateVCWithDic:(NSDictionary *)dic{
    Class cls = NSClassFromString(dic[@"vcName"]);
    UIViewController *vc = [[cls alloc] init];
    vc.title = dic[@"title"];
    vc.tabBarItem.image = [[UIImage imageNamed:[NSString stringWithFormat:@"%@",dic[@"imageName"]]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@选中",dic[@"imageName"]]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //添加一个导航条
    MainNavigationController *navi = [[MainNavigationController alloc] initWithRootViewController:vc];
    
    return navi;
}


@end
